package cn.kpi.common.Excel.export;

import cn.kpi.common.Excel.domain.SubheadModel;
import cn.kpi.common.Excel.export.domain.common.ExportConfig;
import cn.kpi.common.Excel.export.domain.common.ExportResult;
import cn.kpi.common.Excel.export.domain.common.ExportType;
import cn.kpi.common.Excel.export.domain.excel.ExportExcelResult;
import cn.kpi.common.Excel.export.exception.FileExportException;
import cn.kpi.common.Excel.export.impl.ExcelExportor;
import org.apache.poi.ss.usermodel.Workbook;

import java.util.List;

/**
 * Create by liuyong on 2017/11/3
 */

public class FileExportor {
    public final static String EXPORT_XML_BASE_PATH = "/properties/framework/export/";

    /**
     * 通过list<T> T可为bean或者map<String, Object>  导出文件
     *
     * @param exportConfig
     * @param data
     * @return
     * @throws
     */
    public static ExportResult getExportResult(ExportConfig exportConfig, List<?> data, SubheadModel subheadingVo) throws FileExportException {
         ExportType exportType = exportConfig.getExportType();
        switch (exportType) {
            case EXCEL2007:
                Workbook workbook = new ExcelExportor().getExportResult(data, exportConfig.getExportCells(),subheadingVo);
                ExportExcelResult exportExcelResult = new ExportExcelResult();
                exportExcelResult.setWorkbook(workbook);
                exportExcelResult.setFileName(exportConfig.getFileName());
                return exportExcelResult;
            case CSV: ;
                return null;
        }
        throw new FileExportException("找不到对应的export type, export type is " + exportType.getNumber());
    }

    public static ExportResult addSheetResult(ExportResult exportExcelResult, ExportConfig exportConfig, List<?> data, SubheadModel subheadingVo) throws FileExportException {
        ExportType exportType = exportConfig.getExportType();
        Workbook workbook = (Workbook) exportExcelResult.getResult();
        new ExcelExportor().addSheet(workbook,data,exportConfig.getExportCells(),subheadingVo);
        return exportExcelResult;
        }
}
